
class Tool {
    id = 0;

    // attack: number = 10;

    name = "";

    y = 0;

    x = 0;
    pictureS = new Image();
    pictureM = new Image();
    pictureL = new Image();

    view: renderer.DisplayObject;

    instruction = "";

    // parseFromConfig(config: any) {

    // }

    constructor(config: any) {
        this.id = config.id;
        this.name = config.name;

        const avatarUrl1 = config.viewS;
        const picture1 = new Image();
        picture1.src = avatarUrl1;


        const avatarUrl2 = config.viewM;
        const picture2 = new Image();
        picture2.src = avatarUrl2;

        const avatarUrl3 = config.viewL;
        const picture3 = new Image();
        picture3.src = avatarUrl3;


        this.pictureS = picture1;
        const bitmap = new renderer.Bitmap(0, 0, picture1);
        this.view = bitmap;

        this.pictureM = picture2;
        this.pictureL = picture3;

        this.instruction = config.instruction;
    }
}




class ToolManager {

    tools: Tool[] = [];

    parseFromConfig(obj: any) {
        for (let item of obj.tool) {
            const tool = new Tool(item)
            this.tools.push(tool)
        }
    }

    getToolById(id: number) {
        for (let item of this.tools) {
            if (item.id == id) {
                return item;
            }
        }
        throw `missing toolid : ${id}`;
    }
}
const toolManager = new ToolManager();